
#ifndef __SRV_UART_
#define __SRV_UART_
#include "stdint.h"
#include "Platform_Types.h"
#include "FreeRTOSConfig.h"
#include "Ifx_Cfg.h"
#define MAXCHARS            256
#define MAX_MESSAGE         50
#define QUEUE_MAX_SIZE      1000u

#define CLEAR_BIT(dest,offset)  dest &= ~((uint8)1<<offset)
#define SET_BIT(dest,offset)  dest |= (uint8)1<<offset



#define WATCH_STACK(x)   \
uint32 cnt = 0;\
uint32*uCsaAddr = NULL;\
uint32*lCsaAddr = NULL;\
uint32 csa = 0;\
    __dsync();\
    csa = __mfcr( Tricore_PCXI );\
    uCsaAddr = portCSA_TO_ADDRESS( csa );\
    lCsaAddr = portCSA_TO_ADDRESS(uCsaAddr[0]);\
    __isync();\
    static int y = 0;\
    cnt++;\
    extern void Ifx_Lwip_printf(const char *format, ...);\
    y++;\
    if(y== (x/4))\
    {\
       Ifx_Lwip_printf("PSW = %X",uCsaAddr[1]);\
    }\
    else if(y == (x/4*2))\
    {\
       Ifx_Lwip_printf("SP = %X,return addr1 = %X",uCsaAddr[2],uCsaAddr[3]);\
    }\
    else if(y ==  (x/4*3))\
    {\
              Ifx_Lwip_printf("lcsa = %X,",uCsaAddr[0]);\
    }\
    else if(y>x)\
    {\
       y = 0;\
       Ifx_Lwip_printf("return addr2 = %X,",lCsaAddr[1]);\
    }\






typedef struct
{
   uint8 task;
   uint32 tick;
}TASK_INFO;
typedef struct
{
  TASK_INFO tasks[QUEUE_MAX_SIZE];
  uint16 l;
  uint16 r;
  uint16 size;
}UART_FIFO;
#if ANSYS_UART
void uart_print_async(uint8 len,char *s);
#else
#if QZX_WATCH_TASK_SEQ
extern UART_FIFO  uart_quque;
void uart_print_async(uint8 task,uint32 tick);
#endif
#endif

void init_queue();
extern sint8 Ifx_Lwip_printf(const char *format, ...);
void uart_print_task(void);


#if ANSYS_UART
typedef struct
{
    uint8 len;
    char strings[MAXCHARS];
}Ansys_Msg_Type;

typedef struct
{
        uint8 size_cpu0;
        uint8 front_cpu1;
        uint8 rear_cpu0;
        Ansys_Msg_Type msg[MAX_MESSAGE];
}Msg_FiFO_Type;


#endif
#if ANSYS_UART
extern Msg_FiFO_Type debug_info_fifo;
#else
#if QZX_WATCH_TASK_SEQ
#endif
#endif
#endif


